package com.xp.basic.heima.bio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

/**
 * 使用新api实现的bio 客户端
 */
public class NBioClient {


    public static void main(String[] args) throws IOException {
        SocketChannel sc = SocketChannel.open();
        //这里是直接使用客户端连接
        sc.connect(new InetSocketAddress(8899));

        System.out.println("链接上了服务器");

        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
        int count = 0;
        while (true){
            count+= sc.read(buffer);
            System.out.println("count = " + count);
            buffer.clear();
        }

    }
}
